package com.example.searchcenter;

import com.example.searchcenter.R;
import com.example.searchcenter.activity.Activites;
import com.example.searchcenter.article.News;
import com.example.searchcenter.center.Home;
import com.example.searchcenter.funder.Funders;
import com.example.searchcenter.helper.AlertDialogManager;
import com.example.searchcenter.helper.ConnectionDetector;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;

public class Main extends TabActivity {

	// Connection detector
	ConnectionDetector cd;
	// Alert dialog manager
	AlertDialogManager alert = new AlertDialogManager();

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		cd = new ConnectionDetector(getApplicationContext());

		// Check for internet connection
		if (!cd.isConnectingToInternet()) {
			// Internet Connection is not present
			alert.showAlertDialog(Main.this, "Internet Connection Error",
					"Please connect to working Internet connection", false);
			// stop executing code by return
			return;
		}
		setContentView(R.layout.main);
		TabHost tabHost = getTabHost();

		// Tab for Home
		TabSpec homespec = tabHost.newTabSpec("Home");
		homespec.setIndicator("Trung tâm",
				getResources().getDrawable(R.drawable.home_icon));
		Intent homeIntent = new Intent(this, Home.class);
		homespec.setContent(homeIntent);

		// // Tab for News
		TabSpec newsspec = tabHost.newTabSpec("News");
		newsspec.setIndicator("Tin tức",
				getResources().getDrawable(R.drawable.news_icon));
		Intent newsIntent = new Intent(this, News.class);
		newsspec.setContent(newsIntent);
		//
		// // Tab for Activities
		TabSpec actsspec = tabHost.newTabSpec("Hoạt động");
		actsspec.setIndicator("Hoạt động",
				getResources().getDrawable(R.drawable.acti_icon));
		Intent actsIntent = new Intent(this, Activites.class);
		actsspec.setContent(actsIntent);
		
		// Tab for Funders
		TabSpec fundersspec = tabHost.newTabSpec("Funders");
		fundersspec.setIndicator("Tài trợ",
				getResources().getDrawable(R.drawable.funder_icon));
		Intent fundersIntent = new Intent(this, Funders.class);
		fundersspec.setContent(fundersIntent);
		
		// // Tab for About
		// TabSpec aboutsspec = tabHost.newTabSpec("About");
		// aboutsspec.setIndicator("About",
		// getResources().getDrawable(R.drawable.icon_photos_tab));
		// Intent aboutIntent = new Intent(this, AboutActivity.class);
		// aboutsspec.setContent(aboutIntent);
		
		tabHost.addTab(homespec);
		tabHost.addTab(newsspec);
		tabHost.addTab(actsspec);
		tabHost.addTab(fundersspec);
		// tabHost.addTab(aboutsspec);
	}

}
